function [alpha, bias] = onlineperceptron(S, Y, maxgens, granmatrix)
    s = size(S);
    len = s(1);
    alpha = zeros(s(1),1);
    bias = 0;
    R2 = max(sum((S').^2));
    mistakes = zeros(maxgens,1);
    for g=1:maxgens
        for i=1:len
            yi = Y(i);
            acc = sum(alpha.* Y .* granmatrix(:,1));
            if(yi*acc <= 0)
                alpha(i) = alpha(i) + 1;
                bias = bias + yi*R2;
                mistakes(g) = mistakes(g) + 1;
            end                
        end
        if mistakes(g) == 0
            break;
        end
    end    
end